﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using SIS.BLL;
using SIS.ENT;

public partial class student_Guardian_Detail : System.Web.UI.Page
{
    SIS.UI.Common _common = new SIS.UI.Common();

    protected void Page_Load(object sender, EventArgs e)
    {
        lblTopMessage.Text = DateTime.Now.ToString();
        if (!Page.IsPostBack)
        {
            SIS.Utilities.General.LoadDayDropdownList(ddlDOBDay);
            SIS.Utilities.General.LoadMonthDropdownList(ddlDOBMonth, 2);
            SIS.Utilities.General.LoadYearDropdownList(ddlDOBYear, (DateTime.Now.Year - 120), DateTime.Now.Year, 1);

            _common.LoadBloodGroupDDL(ddlBloodGroup, string.Empty);
            _common.LoadMartialStatusCodeDDL(ddlMaritalStatus, string.Empty);
            _common.LoadRaceCodeDDL(ddlRaceCode, string.Empty);
            _common.LoadReligionCodeDDL(ddlReligion, string.Empty);
            _common.LoadNationalityDDL(ddlNationality, string.Empty);
            _common.LoadTravelDocDDL(ddlTravelDocType, string.Empty);
            _common.LoadDrivingLicenseTypeDDL(ddlDrivingLicenceType, string.Empty);
            _common.LoadRelationshipTypeDDL(ddlGSRelation, string.Empty);
            _common.LoadCurrencyCodeDDL(ddlAnnualGrossIncomeCurrencyCode, string.Empty);
            _common.LoadCountryCodeDDL(ddlSRCountry, string.Empty);
            _common.LoadCountryCodeDDL(ddlCountry, string.Empty);
            _common.LoadCountryCodeDDL(ddlBCountry, string.Empty);

            if (Request.Params["id"] != null)
            {

                int _id = -1;
                if (Int32.TryParse(Request.Params["id"].ToString(), out _id))
                {
                    if (LoadStudentInfo(_id))
                    {
                        lblStudentUserAccountKey.Text = _id.ToString();
                        gvRelationList.DataBind();
                        divStudentProfile.Visible = false;
                        divStudentDetails.Visible = true;
                        hplStudent.NavigateUrl = "~/student/?id=" + _id.ToString();
                        lblTopMessage.Text = "Add or Edit Guardian/Family Details - " + DateTime.Now.ToString();
                        //LoadGuardianInfo(_id);
                        //btnRegister.Visible = true;
                    }
                    else
                    {
                        divStudentDetails.Visible = false;
                        divStudentProfile.Visible = false;
                        btnSubmit.Enabled = false;
                        btnNew.Enabled = false;
                        tbcEntry.Enabled = false;
                    }
                }
                else
                {
                    lblTopMessage.Text = "Invalid guardian account ID.";
                }

                //lblTopMessage.Text = DateTime.Now.ToString();
            }
            else
            {
                lblTopMessage.Text = "Add New Guardian/Family - " + DateTime.Now.ToString();
                divStudentProfile.Visible = true;
                btnSubmit.Enabled = false;
                btnNew.Enabled = false;
                tbcEntry.Enabled = false;
            }
        }
    }

    private bool LoadStudentInfo(int AccountID)
    {
        bool _retValue = true;
        UserAccountTable _account = new UserAccountTable();
        _account = UserAccountTableManager.GetItem(AccountID);

        if (_account == null)
        {
            lblTopMessage.Text = "Student account ID (" + AccountID.ToString() + ") is not found!";
            hplStudent.Visible = false;
            _retValue = false;
        }
        else if (_account.UserAccountKey <= 0)
        {
            lblTopMessage.Text = "Student account ID is not found!";
            hplStudent.Visible = false;
            _retValue = false;
        }

        if (_account != null && _account.UserAccountKey > 0)
        {
            if (_account.UserAccountTypeCode != 300)
            {
                lblTopMessage.Text = "Only for student account ID will be loaded.";
                hplStudent.Visible = false;
                _retValue = false;
            }

            lblStudentUserAccountKey.Text = _account.UserAccountKey.ToString();

            StudentProfileTable _sprofile = new StudentProfileTable();
            StudentAddressTable _saddress = new StudentAddressTable();
            StudentContactTable _scontact = new StudentContactTable();
            StudentGuardianRelationshipTable _gsrelation = new StudentGuardianRelationshipTable();

            _sprofile = StudentProfileTableManager.GetItemByUserAccountKey(AccountID);
            if (_sprofile != null && _sprofile.StudentProfileKey > 0)
            {
                lblStudentProfileKey.Text = _sprofile.StudentProfileKey.ToString();
                //txtFirstName.Text = _sprofile.FirstName;
                //txtLastName.Text = _sprofile.LastName;
                //txtOtherName.Text = _sprofile.OtherName;
                string _fullName = string.Empty;
                if (_sprofile.FirstName.Length > 0)
                {
                    _fullName = _sprofile.FirstName;
                }

                if (_sprofile.LastName.Length > 0)
                {
                    _fullName += " " + _sprofile.LastName;
                }

                if (_sprofile.OtherName.Length > 0)
                {
                    _fullName += " &lt;or&gt; " + _sprofile.OtherName;
                }
                //lblFullName.Text = _fullName;

                DateTime _dtDOB = _sprofile.DateOfBirth;
                int _age = DateTime.Now.Year - _dtDOB.Year;
                _fullName += " (" + _sprofile.Gender + ", " + _age.ToString() + " yrs)";
                lblStudentFullName.Text = _fullName;
                lblStudentNRICNumber.Text = _sprofile.NRICNumber;

                //ddlDOBDay.Text = _dtDOB.Day.ToString("00");
                //ddlDOBMonth.Text = _dtDOB.Month.ToString("00");
                //ddlDOBYear.Text = _dtDOB.Year.ToString("0000");

                //txtNRICNumber.Text = _sprofile.NRICNumber;
                //ddlDrivingLicenceType.Text = _sprofile.DrivingLicenceType.ToString();
                //txtDrivingLicenceNumber.Text = _sprofile.DrivingLicenseNumber;

                //ddlTravelDocType.Text = _sprofile.TravelDocumentType.ToString();
                //txtTravelDocNumber.Text = _sprofile.TravelDocumentNumber;

                //ddlBloodGroup.Text = _sprofile.BloodGroupCode.ToString();
                //ddlMaritalStatus.Text = _sprofile.MartialStatusCode.ToString();
                //ddlRaceCode.Text = _sprofile.RaceCode.ToString();
                //ddlReligion.Text = _sprofile.ReligionCode.ToString();
                //ddlNationality.Text = _sprofile.NationalityCode.ToString();
                //txtWebsiteUrl.Text = _sprofile.WebSiteUrl;
                //txtDisablityRemark.Text = _sprofile.DisabilityRemark;
                //txtRemark.Text = _sprofile.Remark;
            }
            else
            {
                _retValue = false;
            }

            _saddress = StudentAddressTableManager.GetItemByUserAccountKey(AccountID, 1);
            if (_saddress != null && _saddress.StudentAddressKey > 0)
            {
                //lblStudentAddressKey.Text = _saddress.StudentAddressKey.ToString();
                txtSRUnitNo.Text = _saddress.UnitNo;
                txtSRStreetName.Text = _saddress.StreetName;
                ddlSRCountry.Text = _saddress.CountryCode.ToString();
                ddlSRCountry_SelectedIndexChanged(null, null);

                ddlSRDistrict.Text = _saddress.DistrictCode.ToString();
                ddlSRDistrict_SelectedIndexChanged(null, null);
                ddlSRCity.Text = _saddress.CityCode.ToString();


                txtSRPostCode.Text = _saddress.PostalCode;

                lblStudentAddressInfo.Text = txtSRUnitNo.Text + ", ";
                lblStudentAddressInfo.Text += txtSRStreetName.Text + ", ";
                lblStudentAddressInfo.Text += ddlSRCity.SelectedItem.Text + ", " + ddlSRDistrict.SelectedItem.Text + ", ";
                lblStudentAddressInfo.Text += ddlSRCountry.SelectedItem.Text;

                divStudentAddressInfo.Visible = false;
                txtSRUnitNo.Enabled = false;
                txtSRStreetName.Enabled = false;
                ddlSRCity.Enabled = false;
                ddlSRDistrict.Enabled = false;
                ddlSRCountry.Enabled = false;
                txtSRPostCode.Enabled = false;
            }
            else
            {
                _retValue = false;
            }

            _scontact = StudentContactTableManager.GetItemByUserAccountKey(AccountID);
            if (_scontact != null && _scontact.StudentContactKey > 0)
            {
                string _contactInfo = string.Empty;
                if (_scontact.MobileNumber != null && _scontact.MobileNumber.Length > 0)
                {
                    _contactInfo = "Mobile: " + _scontact.MobileNumber;
                }

                if (_scontact.HomePhoneNumber != null && _scontact.HomePhoneNumber.Length > 0)
                {
                    if (_contactInfo.Length > 0)
                    {
                        _contactInfo += ", ";
                    }
                    _contactInfo += "Home: " + _scontact.HomePhoneNumber;
                }

                if (_scontact.OtherNumber != null && _scontact.OtherNumber.Length > 0)
                {
                    if (_contactInfo.Length > 0)
                    {
                        _contactInfo += ", ";
                    }

                    _contactInfo += "Other: " + _scontact.OtherNumber;
                }

                if (_scontact.EmailAddress != null && _scontact.EmailAddress.Length > 0)
                {
                    if (_contactInfo.Length > 0)
                    {
                        _contactInfo += ", ";
                    }

                    _contactInfo += "Email: " + _scontact.EmailAddress;
                }

                lblStudentContactInfo.Text = _contactInfo;
                //lblStudentContactKey.Text = _scontact.StudentContactKey.ToString();
                //txtMobileNumber.Text = _scontact.MobileNumber;
                //txtHomePhoneNumber.Text = _scontact.HomePhoneNumber;
                //txtEmailAddress.Text = _scontact.EmailAddress;
                //txtOtherContactNumber.Text = _scontact.OtherNumber;
            }
            else
            {
                _retValue = false;
            }
        }

        return _retValue;
    }

    private void LoadGuardianInfo(int AccountID)
    {
        UserAccountTable _account = new UserAccountTable();
        _account = UserAccountTableManager.GetItem(AccountID);

        if (_account == null)
        {
            lblTopMessage.Text = "Guardian account ID (" + AccountID.ToString() + ") is not found!";
        }
        else if (_account.UserAccountKey <= 0)
        {
            lblTopMessage.Text = "Guardian account ID is not found!";
        }

        if (_account != null && _account.UserAccountKey > 0)
        {
            if (_account.UserAccountTypeCode != 700)
            {
                lblTopMessage.Text = "Only for Guardian account ID will be loaded.";
                return;
            }

            lblGuardianAccountKey.Text = _account.UserAccountKey.ToString();

            GuardianProfileTable _profile = new GuardianProfileTable();

            GuardianAddressTable _address = new GuardianAddressTable();

            GuardianContactTable _contact = new GuardianContactTable();
            StudentGuardianRelationshipTable _gsrelation = new StudentGuardianRelationshipTable();

            _profile = GuardianProfileTableManager.GetItemByUserAccountKey(AccountID);
            if (_profile != null && _profile.GuardianProfileKey > 0)
            {
                lblGuardianProfileKey.Text = _profile.GuardianProfileKey.ToString();
                txtFirstName.Text = _profile.FirstName;
                txtLastName.Text = _profile.LastName;
                txtOtherName.Text = _profile.OtherName;
                ddlGender.Text = _profile.Gender;

                DateTime _dtDOB = _profile.DateOfBirth;
                ddlDOBDay.Text = _dtDOB.Day.ToString("00");
                ddlDOBMonth.Text = _dtDOB.Month.ToString("00");
                ddlDOBYear.Text = _dtDOB.Year.ToString("0000");

                txtNRICNumber.Text = _profile.NRICNumber;

                txtHighestEducation.Text = _profile.HighestEducation;
                txtOccupation.Text = _profile.Occupation;
                txtCompanyName.Text = _profile.CompanyName;
                txtCompanyIndustry.Text = _profile.CompanyIndustry;
                txtDesignation.Text = _profile.Designation;
                ddlCompanySize.Text = _profile.CompanySize.ToString();
                txtAnnualGrossIncome.Text = _profile.AnnualGrossIncome.ToString("#,000.00");
                if (_profile.AnnualGrossIncomeCurrencyCode > 0)
                {
                    if (ddlAnnualGrossIncomeCurrencyCode.Items.Count > 0)
                    {
                        ddlAnnualGrossIncomeCurrencyCode.Text = _profile.AnnualGrossIncomeCurrencyCode.ToString();
                    }
                }
                else
                {
                    if (ddlAnnualGrossIncomeCurrencyCode.Items.Count > 0)
                    {
                        ddlAnnualGrossIncomeCurrencyCode.SelectedIndex = 0;
                    }
                }

                ddlDrivingLicenceType.Text = _profile.DrivingLicenceType.ToString();
                txtDrivingLicenceNumber.Text = _profile.DrivingLicenseNumber;

                ddlTravelDocType.Text = _profile.TravelDocumentType.ToString();
                txtTravelDocNumber.Text = _profile.TravelDocumentNumber;

                ddlBloodGroup.Text = _profile.BloodGroupCode.ToString();
                ddlMaritalStatus.Text = _profile.MartialStatusCode.ToString();
                ddlRaceCode.Text = _profile.RaceCode.ToString();
                ddlReligion.Text = _profile.ReligionCode.ToString();
                ddlNationality.Text = _profile.NationalityCode.ToString();
                txtWebsiteUrl.Text = _profile.WebSiteUrl;
                //txtDisablityRemark.Text = _profile.DisabilityRemark;
                //txtRemark.Text = _profile.Remark;
            }

            //Resident
            _address = GuardianAddressTableManager.GetItemByUserAccountKey(AccountID, 1);
            if (_address != null && _address.GuardianAddressKey > 0)
            {
                lblGuardianPAddressKey.Text = _address.GuardianAddressKey.ToString();
                chkSameAsResident.Checked = _address.SameAsStudentResidentAddress;
                chkSameAsResident_CheckedChanged(null, null);

                if (chkSameAsResident.Checked == false)
                {
                    txtUnitNo.Text = _address.UnitNo;
                    txtStreetName.Text = _address.StreetName;
                    ddlCountry.Text = _address.CountryCode.ToString();
                    ddlCountry_SelectedIndexChanged(null, null);

                    ddlDistrict.Text = _address.DistrictCode.ToString();
                    ddlDistrict_SelectedIndexChanged(null, null);

                    ddlCity.Text = _address.CityCode.ToString();

                    txtPostCode.Text = _address.PostalCode;
                }
            }

            //Business
            _address = GuardianAddressTableManager.GetItemByUserAccountKey(AccountID, 2);
            if (_address != null && _address.GuardianAddressKey > 0)
            {
                lblGuardianBAddressKey.Text = _address.GuardianAddressKey.ToString();

                txtBUnitNo.Text = _address.UnitNo;
                txtBStreetName.Text = _address.StreetName;
                if (_address.CountryCode != null && _address.CountryCode > 0)
                {
                    ddlBCountry.Text = _address.CountryCode.ToString();
                    ddlBCountry_SelectedIndexChanged(null, null);

                    if (_address.DistrictCode != null && _address.DistrictCode > 0)
                    {
                        ddlBDistrict.Text = _address.DistrictCode.ToString();
                        ddlBDistrict_SelectedIndexChanged(null, null);

                        if (ddlBCity.Items.Count > 0 && _address.CityCode != null && _address.CityCode > 0)
                        {
                            ddlBCity.Text = _address.CityCode.ToString();
                        }
                    }
                }
                txtBPostCode.Text = _address.PostalCode;

            }

            //Permanent/Contact
            //_spaddress = StudentAddressTableManager.GetItemByUserAccountKey(AccountID, 2);
            //if (_spaddress != null && _spaddress.StudentAddressKey > 0)
            //{
            //    lblStudentPAddressKey.Text = _spaddress.StudentAddressKey.ToString();
            //    txtPUnitNo.Text = _spaddress.UnitNo;
            //    txtPStreetName.Text = _spaddress.StreetName;
            //    ddlPCity.Text = _spaddress.CityCode.ToString();
            //    ddlPDistrict.Text = _spaddress.DistrictCode.ToString();
            //    ddlPCountry.Text = _spaddress.CountryCode.ToString();
            //    txtPPostCode.Text = _spaddress.PostalCode;
            //    chkPSameAsResident.Checked = _spaddress.SameAsResident;
            //    chkPSameAsResident_CheckedChanged(null, null);
            //}

            //Mailing
            //_smaddress = StudentAddressTableManager.GetItemByUserAccountKey(AccountID, 3);
            //if (_smaddress != null && _smaddress.StudentAddressKey > 0)
            //{
            //    lblStudentMAddressKey.Text = _smaddress.StudentAddressKey.ToString();
            //    txtMUnitNo.Text = _smaddress.UnitNo;
            //    txtMStreetName.Text = _smaddress.StreetName;
            //    ddlMCity.Text = _smaddress.CityCode.ToString();
            //    ddlMDistrict.Text = _smaddress.DistrictCode.ToString();
            //    ddlMCountry.Text = _smaddress.CountryCode.ToString();
            //    txtMPostCode.Text = _smaddress.PostalCode;
            //    chkMSameAsResident.Checked = _smaddress.SameAsResident;
            //    chkMSameAsResident_CheckedChanged(null, null);
            //}

            _contact = GuardianContactTableManager.GetItemByUserAccountKey(AccountID);
            if (_contact != null && _contact.GuardianContactKey > 0)
            {
                lblGuardianContactKey.Text = _contact.GuardianContactKey.ToString();
                txtMobileNumber.Text = _contact.MobileNumber;
                txtHomePhoneNumber.Text = _contact.HomePhoneNumber;
                txtFaxNumber.Text = _contact.FaxNumber;
                txtOfficePhoneNumber.Text = _contact.OfficePhoneNumber;
                txtEmailAddress.Text = _contact.EmailAddress;
                txtOtherContactNumber.Text = _contact.OtherNumber;
            }

            _gsrelation = StudentGuardianRelationshipTableManager.GetItemByGuardianAccountKey(_profile.UserAccountKey);
            if (_gsrelation != null && _gsrelation.GuardianAccountKey > 0)
            {
                lblStudentGuardianRelationTypeKey.Text = _gsrelation.GSAutoID.ToString();
                ddlGSRelation.Text = _gsrelation.RelationshipTypeCode.ToString();
                chkIsMainGuardian.Checked = _gsrelation.IsMainGuardian;
            }
            //if (_gsrelation != null && _gsrelation.GuardianAccountKey > 0)
            //{
            //    lblStudentGuardianRelationTypeKey.Text = _gsrelation.GSAutoID.ToString();
            //    UserAccountTable _gaccount = new UserAccountTable();
            //    _gaccount = UserAccountTableManager.GetItem(_gsrelation.GuardianAccountKey);

            //    if (_gaccount != null && _gaccount.UserAccountKey > 0)
            //    {
            //        lblGuardianAccountKey.Text = _gaccount.UserAccountKey.ToString();
            //        GuardianProfileTable _gprofile = new GuardianProfileTable();
            //        GuardianAddressTable _gaddress = new GuardianAddressTable();
            //        GuardianContactTable _gcontact = new GuardianContactTable();

            //        _gprofile = GuardianProfileTableManager.GetItemByUserAccountKey(_gaccount.UserAccountKey);
            //        if (_gprofile != null && _gprofile.GuardianProfileKey > 0)
            //        {
            //            lblGuardianProfileKey.Text = _gprofile.GuardianProfileKey.ToString();
            //            txtGuardianFirstName.Text = _gprofile.FirstName;
            //            txtGuardianLastName.Text = _gprofile.LastName;
            //            DateTime _dtGDOB = _gprofile.DateOfBirth;
            //            ddlGuardianDOBDay.Text = _dtGDOB.Day.ToString("00");
            //            ddlGuardianDOBMonth.Text = _dtGDOB.Month.ToString("00");
            //            ddlGuardianDOBYear.Text = _dtGDOB.Year.ToString("0000");
            //            ddlGuardianRelationshipType.Text = _gsrelation.RelationshipTypeCode.ToString();
            //        }

            //        _gaddress = GuardianAddressTableManager.GetItemByUserAccountKey(_gaccount.UserAccountKey);
            //        if (_gaddress != null && _gaddress.GuardianAddressKey > 0)
            //        {
            //            lblGuardianAddressKey.Text = _gaddress.GuardianAddressKey.ToString();
            //            txtGuardianAddressUnitNo.Text = _gaddress.UnitNo;
            //            txtGuardianAddressStreet.Text = _gaddress.StreetName;
            //            txtGuardianAddressPostal.Text = _gaddress.PostalCode;
            //            ddlGuardianAddressCountry.Text = _gaddress.CountryCode.ToString();
            //            chkGuardianSameAsResident.Checked = _gaddress.SameAsStudentResidentAddress;
            //            chkGuardianSameAsResident_CheckedChanged(null, null);
            //        }

            //        _gcontact = GuardianContactTableManager.GetItemByUserAccountKey(_gaccount.UserAccountKey);
            //        if (_gcontact != null && _gcontact.GuardianContactKey > 0)
            //        {
            //            lblGuardianContactKey.Text = _gcontact.GuardianContactKey.ToString();
            //            txtGuardianOtherContactNumber.Text = _gcontact.OtherNumber;
            //            txtGuardianEmailAddress.Text = _gcontact.EmailAddress;
            //            txtGuardianHomePhoneNumber.Text = _gcontact.HomePhoneNumber;
            //            txtGuardianMobileNumber.Text = _gcontact.MobileNumber;
            //        }
            //    }
            //}
        }

    }

    protected void ddlSchoolList_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

    protected void btnShowStudentProfile_Click(object sender, EventArgs e)
    {

    }

    private bool CheckValidation()
    {
        bool _retValue = true;

        if (txtEmailAddress.Text.Trim().Length <= 0 &&
                txtMobileNumber.Text.Trim().Length <= 0 &&
                txtOtherContactNumber.Text.Trim().Length <= 0 &&
                txtHomePhoneNumber.Text.Trim().Length <= 0)
        {
            lblMessage.Text += "Guardian contacts are blank!<br/>";

            _retValue = false;
        }

        //if (Convert.ToInt16(ddlGuardianRelationshipType.Text) <= 0 ||
        //        (txtGuardianFirstName.Text.Trim().Length <= 0 && txtGuardianLastName.Text.Trim().Length <= 0)
        //    || (txtGuardianHomePhoneNumber.Text.Trim().Length <= 0 && txtGuardianMobileNumber.Text.Trim().Length <= 0)
        //    || (txtGuardianAddressPostal.Text.Trim().Length <= 0 && Convert.ToInt16(ddlGuardianAddressCountry.Text) <= 0))
        //{
        //    lblMessage.Text += "Guardian's details are blank or not sufficient!<br/>";
        //    _retValue = false;
        //}

        csvContactNumbers.Validate();
        //csvGuardianContactNumbers.Validate();
        csvDOB.Validate();
        //csvGuardianDOB.Validate();

        ChangeServerSideValidationEffect();
        lblTopMessage.Text = lblMessage.Text;
        return _retValue;
    }

    /// <summary>
    /// Saving all guaridan details
    /// Check AccountKey and create new one if not found
    /// Saving Profile
    /// Saving Addresses
    /// Saving Contact
    /// Saving Guardian & Relationship type
    /// Saving Other Details
    /// Last Modified 16/April/2012 2:47 PM (Phyo Kyaw Thant)
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// 

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        lblMessage.Text = "";
        btnRegister.Visible = false;
        bool _status = true;
        Page.Validate("GuardianProfile");
        if (Page.IsValid && CheckValidation())
        {
            UserAccountTable _account = new UserAccountTable();
            _account.UserAccountKey = Convert.ToInt32(lblGuardianAccountKey.Text);
            _account.SchoolKey = Convert.ToInt32(ddlSchoolList.Text);
            if (_account.UserAccountKey <= 0)
            {
                _account.UserAccountTypeCode = 700;
                _account.AuthCode = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 6);
                _account.AuthSalt = "GuardianGUID" + _account.AuthCode;

                _account.UserAccountAlternateKey = txtFirstName.Text.Replace(" ", ".") + txtLastName.Text.Replace(" ", ".") + "@" + ddlSchoolList.Text;
                lblGuardianAccountAuthCode.Text = _account.UserAccountAlternateKey + " With " + _account.AuthCode + " salted " + _account.AuthSalt;
                _account.Status = -1;

                UserAccountTableManager.Save(_account).ToString();

                if (_account.UserAccountKey <= 0)
                {
                    lblMessage.Text = "Saving guardian user account was failed!";
                    _status = false;
                    return;
                }
                else
                {
                    lblGuardianAccountKey.Text = _account.UserAccountKey.ToString();
                }
            }

            GuardianProfileTable _profile = new GuardianProfileTable();

            GuardianContactTable _contact = new GuardianContactTable();

            GuardianAddressTable _address = new GuardianAddressTable();

            _profile.UserAccountKey = _account.UserAccountKey;
            _contact.UserAccountKey = _account.UserAccountKey;
            _address.UserAccountKey = _account.UserAccountKey;

            _profile.GuardianProfileKey = Convert.ToInt32(lblGuardianProfileKey.Text);
            _contact.GuardianContactKey = Convert.ToInt32(lblGuardianContactKey.Text);
            

            _profile.FirstName = txtFirstName.Text;
            _profile.LastName = txtLastName.Text;
            _profile.OtherName = txtOtherName.Text;

            DateTime _dtDOB = DateTime.Now;
            string _strDOB = string.Empty;
            _profile.DateOfBirth = new DateTime(1900, 1, 1);

            _profile.Gender = ddlGender.Text;
            _strDOB = ddlDOBDay.Text + "/" + ddlDOBMonth.SelectedItem.Text + "/" + ddlDOBYear.Text.ToString();
            if (SIS.Utilities.General.GetDateTime(_strDOB, out _dtDOB))
            {
                _profile.DateOfBirth = _dtDOB;
                //lblMessage.Text += "User DOB: " + _dtDOB.ToString("dd/MMM/yyyy") + "<br/>";
            }
            else
            {
                //lblMessage.Text += _strDOB + " " + "NO User DOB: " + _dtDOB.ToString("dd/MMM/yyyy") + "<br/>";
            }

            _profile.HighestEducation = txtHighestEducation.Text;
            _profile.Occupation = txtOccupation.Text;
            _profile.CompanyName = txtCompanyName.Text;
            _profile.Designation = txtDesignation.Text;
            _profile.CompanyIndustry = txtCompanyIndustry.Text;
            _profile.CompanySize = Convert.ToInt16(ddlCompanySize.Text);

            decimal _annIncome = 0.0M;
            if (decimal.TryParse(txtAnnualGrossIncome.Text, out _annIncome))
            {
                _profile.AnnualGrossIncome = _annIncome;
            }
            _profile.AnnualGrossIncomeCurrencyCode = Convert.ToInt16(ddlAnnualGrossIncomeCurrencyCode.Text);

            _profile.NRICNumber = txtNRICNumber.Text;

            _profile.DrivingLicenceType = Convert.ToInt16(ddlDrivingLicenceType.Text);
            _profile.DrivingLicenseNumber = txtDrivingLicenceNumber.Text;

            _profile.TravelDocumentType = Convert.ToInt16(ddlTravelDocType.Text);
            _profile.TravelDocumentNumber = txtTravelDocNumber.Text;

            _profile.BloodGroupCode = Convert.ToInt16(ddlBloodGroup.Text);
            _profile.MartialStatusCode = Convert.ToInt16(ddlMaritalStatus.Text);
            _profile.RaceCode = Convert.ToInt16(ddlRaceCode.Text);
            _profile.ReligionCode = Convert.ToInt16(ddlReligion.Text);
            _profile.NationalityCode = Convert.ToInt16(ddlNationality.Text);
            _profile.WebSiteUrl = txtWebsiteUrl.Text;

            GuardianProfileTableManager.Save(_profile);

            if (_profile.GuardianProfileKey <= 0)
            {
                lblMessage.Text += "Saving profile was failed!<br/>";
                _status = false;
                //lblStudentProfileKey.Text = "-1";
            }
            else
            {
                lblGuardianProfileKey.Text = _profile.GuardianProfileKey.ToString();
                //lblMessage.Text += "Saving profile was succeeded!<br/>";
            }


            _contact.EmailAddress = txtEmailAddress.Text;
            _contact.MobileNumber = txtMobileNumber.Text;
            _contact.HomePhoneNumber = txtHomePhoneNumber.Text;
            _contact.OtherNumber = txtOtherContactNumber.Text;
            _contact.FaxNumber = txtFaxNumber.Text;
            _contact.OfficePhoneNumber = txtOfficePhoneNumber.Text;
            GuardianContactTableManager.Save(_contact);


            if (_contact.GuardianContactKey <= 0)
            {
                lblMessage.Text += "Saving contact was failed!<br/>";
                _status = false;
                //lblStudentContactKey.Text = "-1";
            }
            else
            {
                lblGuardianContactKey.Text = _contact.GuardianContactKey.ToString();
            }

            //Resident Address
            _address.GuardianAddressKey = Convert.ToInt32(lblGuardianPAddressKey.Text);
            _address.SameAsStudentResidentAddress = chkSameAsResident.Checked;

            if (_address.SameAsStudentResidentAddress)
            {
                _address.UnitNo = txtSRUnitNo.Text;
                _address.StreetName = txtSRStreetName.Text;
                _address.CountryCode = Convert.ToInt16(ddlSRCountry.Text);
                _address.DistrictCode = Convert.ToInt16(ddlSRDistrict.Text);
                _address.CityCode = Convert.ToInt16(ddlSRCity.Text);
                _address.PostalCode = txtSRPostCode.Text;
            }
            else
            {
                _address.UnitNo = txtUnitNo.Text;
                _address.StreetName = txtStreetName.Text;
                _address.CountryCode = Convert.ToInt16(ddlCountry.Text);
                _address.DistrictCode = Convert.ToInt16(ddlDistrict.Text);
                _address.CityCode = Convert.ToInt16(ddlCity.Text);
                _address.PostalCode = txtPostCode.Text;
            }

            _address.AddressTypeCode = 1;

            GuardianAddressTableManager.Save(_address);

            if (_address.GuardianAddressKey <= 0)
            {
                lblMessage.Text += "Saving Resident address was failed!<br/>";
                _status = false;
                //lblStudentAddressKey.Text = "-1";
            }
            else
            {
                lblGuardianPAddressKey.Text = _address.GuardianAddressKey.ToString();
            }

            //Business Address
            _address.GuardianAddressKey = Convert.ToInt32(lblGuardianBAddressKey.Text);
            _address.UnitNo = txtBUnitNo.Text;
            _address.StreetName = txtBStreetName.Text;
            if (ddlBCountry.Text != "" && ddlBCountry.Text != "-1")
            {
                _address.CountryCode = Convert.ToInt16(ddlBCountry.Text);
            }
            if (ddlBDistrict.Text != "" && ddlBDistrict.Text != "-1")
            {
                _address.DistrictCode = Convert.ToInt16(ddlBDistrict.Text);
            }

            if (ddlBCity.Text != "" && ddlBCity.Text != "-1")
            {
                _address.CityCode = Convert.ToInt16(ddlBCity.Text);
            }

            _address.PostalCode = txtBPostCode.Text;

            _address.AddressTypeCode = 2;

            GuardianAddressTableManager.Save(_address);

            if (_address.GuardianAddressKey <= 0)
            {
                lblMessage.Text += "Saving Business address was failed!<br/>";
                _status = false;
                //lblStudentAddressKey.Text = "-1";
            }
            else
            {
                lblGuardianBAddressKey.Text = _address.GuardianAddressKey.ToString();
            }

            //Permanent Address
            //_spaddress.SameAsResident = chkPSameAsResident.Checked;

            //if (_spaddress.SameAsResident)
            //{
            //    _spaddress.UnitNo = txtUnitNo.Text;
            //    _spaddress.StreetName = txtStreetName.Text;
            //    _spaddress.CountryCode = Convert.ToInt16(ddlCountry.Text);
            //    _spaddress.DistrictCode = Convert.ToInt16(ddlDistrict.Text);
            //    _spaddress.CityCode = Convert.ToInt16(ddlCity.Text);
            //    _spaddress.PostalCode = txtPostCode.Text;
            //}
            //else
            //{
            //    _spaddress.UnitNo = txtPUnitNo.Text;
            //    _spaddress.StreetName = txtPStreetName.Text;
            //    _spaddress.CountryCode = Convert.ToInt16(ddlPCountry.Text);
            //    _spaddress.DistrictCode = Convert.ToInt16(ddlPDistrict.Text);
            //    _spaddress.CityCode = Convert.ToInt16(ddlPCity.Text);
            //    _spaddress.PostalCode = txtPPostCode.Text;
            //}

            //_spaddress.AddressTypeCode = 2;

            //StudentAddressTableManager.Save(_spaddress);

            //if (_spaddress.StudentAddressKey <= 0)
            //{
            //    lblMessage.Text += "Saving Permanent address was failed!<br/>";
            //    _status = false;
            //}
            //else
            //{
            //    lblStudentPAddressKey.Text = _spaddress.StudentAddressKey.ToString();
            //}

            //Mailing Address
            //_smaddress.SameAsResident = chkMSameAsResident.Checked;
            //if (_smaddress.SameAsResident)
            //{
            //    _smaddress.UnitNo = txtUnitNo.Text;
            //    _smaddress.StreetName = txtStreetName.Text;
            //    _smaddress.CountryCode = Convert.ToInt16(ddlCountry.Text);
            //    _smaddress.DistrictCode = Convert.ToInt16(ddlDistrict.Text);
            //    _smaddress.CityCode = Convert.ToInt16(ddlCity.Text);
            //    _smaddress.PostalCode = txtPostCode.Text;
            //}
            //else
            //{
            //    _smaddress.UnitNo = txtMUnitNo.Text;
            //    _smaddress.StreetName = txtMStreetName.Text;
            //    _smaddress.CountryCode = Convert.ToInt16(ddlMCountry.Text);
            //    _smaddress.DistrictCode = Convert.ToInt16(ddlMDistrict.Text);
            //    _smaddress.CityCode = Convert.ToInt16(ddlMCity.Text);
            //    _smaddress.PostalCode = txtMPostCode.Text;
            //}

            //_smaddress.AddressTypeCode = 3;
            //StudentAddressTableManager.Save(_smaddress);

            //if (_smaddress.StudentAddressKey <= 0)
            //{
            //    lblMessage.Text += "Saving Mailing address was failed!<br/>";
            //    _status = false;
            //}
            //else
            //{
            //    lblStudentMAddressKey.Text = _smaddress.StudentAddressKey.ToString();
            //}


            //if (Convert.ToInt16(ddlGuardianRelationshipType.Text) > 0 &&
            //    (txtGuardianFirstName.Text.Trim().Length > 0 || txtGuardianLastName.Text.Trim().Length > 0))
            //{
            //    UserAccountTable _gaccount = new UserAccountTable();
            //    _gaccount.UserAccountKey = Convert.ToInt32(lblGuardianAccountKey.Text);
            //    _gaccount.SchoolKey = Convert.ToInt32(ddlSchoolList.Text);
            //    if (_gaccount.UserAccountKey <= 0)
            //    {
            //        _gaccount.UserAccountTypeCode = 700;
            //        _gaccount.AuthCode = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 6);
            //        _gaccount.AuthSalt = "StudentGuardianGUID" + _gaccount.AuthCode;

            //        _gaccount.UserAccountAlternateKey = txtGuardianFirstName.Text.Replace(" ", ".") + txtGuardianLastName.Text.Replace(" ", ".") + "@" + ddlSchoolList.Text;
            //        lblGuardianAccountAuthCode.Text = _gaccount.UserAccountAlternateKey + " With " + _gaccount.AuthCode + " salted " + _gaccount.AuthSalt;

            //        _gaccount.Status = -1;
            //        UserAccountTableManager.Save(_gaccount);

            //        if (_gaccount.UserAccountKey <= 0)
            //        {
            //            lblMessage.Text = "Saving guardian user account was failed!";
            //            _status = false;
            //            return;
            //        }
            //        else
            //        {
            //            lblGuardianAccountKey.Text = _gaccount.UserAccountKey.ToString();
            //        }
            //    }

            StudentGuardianRelationshipTable _gsrelation = new StudentGuardianRelationshipTable();
            _gsrelation.RelationshipTypeCode = Convert.ToInt16(ddlGSRelation.Text);
            _gsrelation.GSAutoID = Convert.ToInt32(lblStudentGuardianRelationTypeKey.Text);
            _gsrelation.StudentAccountKey = Convert.ToInt32(lblStudentUserAccountKey.Text);
            _gsrelation.GuardianAccountKey = _account.UserAccountKey;
            _gsrelation.EmergencyContact = txtMobileNumber.Text.Trim().ToString().Length >= 0 ? txtMobileNumber.Text : txtHomePhoneNumber.Text;
            _gsrelation.IsMainGuardian = chkIsMainGuardian.Checked;
            _gsrelation.Status = true;
            StudentGuardianRelationshipTableManager.Save(_gsrelation);

            if (_gsrelation.GSAutoID <= 0)
            {
                lblMessage.Text = "Saving student and guardian relation status was failed!";
                _status = false;
                return;
            }
            else
            {
                lblStudentGuardianRelationTypeKey.Text = _gsrelation.GSAutoID.ToString();
            }
            //}

            if (lblMessage.Text.Length == 0)
            {
                lblTopMessage.Text = "Saving was succeeded at " + DateTime.Now.ToString("dd/MMM/yyyy hh:mm tt");
                lblMessage.Text = "Saving was succeeded at" + DateTime.Now.ToString("dd/MMM/yyyy hh:mm tt");
            }

            btnRegister.Visible = _status;
            gvRelationList.DataBind();
        }

    }

    protected void btnViewStudentList_Click(object sender, EventArgs e)
    {
        //Response.Redirect("student-list.aspx");
    }

    protected void btnRegisterStudent_Click(object sender, EventArgs e)
    {
        //if (Convert.ToInt32(lblUserAccountKey.Text) > 0)
        //{
        //    Response.Redirect("student-registration.aspx?id=" + lblUserAccountKey.Text.ToString());
        //}
        //else
        //{
        //    lblTopMessage.Text = "Please save current student record.";
        //    lblMessage.Text = "Please save current student record.";
        //    btnRegister.Visible = false;
        //}
    }

    protected void chkPSameAsResident_CheckedChanged(object sender, EventArgs e)
    {
        //divPUnitNo.Visible = !chkPSameAsResident.Checked;
        //divPStreetName.Visible = !chkPSameAsResident.Checked;
        //divPCountry.Visible = !chkPSameAsResident.Checked;
        //divPCity.Visible = !chkPSameAsResident.Checked;

        //rfvPUnitNo.Enabled = !chkPSameAsResident.Checked;
        //rfvPStreetName.Enabled = !chkPSameAsResident.Checked;
        //rfvPCountry.Enabled = !chkPSameAsResident.Checked;
        //rfvPDistrict.Enabled = !chkPSameAsResident.Checked;
        //rfvPCity.Enabled = !chkPSameAsResident.Checked;
        //rfvPPostCode.Enabled = !chkPSameAsResident.Checked;

        //if (chkPSameAsResident.Checked)
        //{
        //    chkPSameAsResident.ForeColor = System.Drawing.Color.Red;
        //}
        //else
        //{
        //    chkPSameAsResident.ForeColor = System.Drawing.Color.Green;
        //}
    }

    protected void chkMSameAsResident_CheckedChanged(object sender, EventArgs e)
    {
        //divMUnitNo.Visible = !chkMSameAsResident.Checked;
        //divMStreetName.Visible = !chkMSameAsResident.Checked;
        //divMCountry.Visible = !chkMSameAsResident.Checked;
        //divMCity.Visible = !chkMSameAsResident.Checked;

        //rfvMUnitNo.Enabled = !chkMSameAsResident.Checked;
        //rfvMStreetName.Enabled = !chkMSameAsResident.Checked;
        //rfvMCountry.Enabled = !chkMSameAsResident.Checked;
        //rfvMDistrict.Enabled = !chkMSameAsResident.Checked;
        //rfvMCity.Enabled = !chkMSameAsResident.Checked;
        //rfvMPostCode.Enabled = !chkMSameAsResident.Checked;

        //if (chkMSameAsResident.Checked)
        //{
        //    chkMSameAsResident.ForeColor = System.Drawing.Color.Red;
        //}
        //else
        //{
        //    chkMSameAsResident.ForeColor = System.Drawing.Color.Green;
        //}
    }

    private void ChangeServerSideValidationEffect()
    {

        if (csvContactNumbers.IsValid)
        {
            txtEmailAddress.ControlStyle.CssClass = "";
            txtHomePhoneNumber.ControlStyle.CssClass = "";
            txtMobileNumber.ControlStyle.CssClass = "";
            txtOtherContactNumber.ControlStyle.CssClass = "";
        }
        else
        {
            txtEmailAddress.ControlStyle.CssClass = "validationError";
            txtHomePhoneNumber.ControlStyle.CssClass = "validationError";
            txtMobileNumber.ControlStyle.CssClass = "validationError";
            txtOtherContactNumber.ControlStyle.CssClass = "validationError";
        }

        if (csvDOB.IsValid)
        {
            ddlDOBDay.ControlStyle.CssClass = "";
            ddlDOBMonth.ControlStyle.CssClass = "";
            ddlDOBYear.ControlStyle.CssClass = "";
        }
        else
        {
            ddlDOBDay.ControlStyle.CssClass = "validationError";
            ddlDOBMonth.ControlStyle.CssClass = "validationError";
            ddlDOBYear.ControlStyle.CssClass = "validationError";
        }

    }

    protected void ContactNumbers_ServerSideValidate(object source, ServerValidateEventArgs args)
    {
        bool _retValue = true;

        txtHomePhoneNumber.Text = txtHomePhoneNumber.Text.Trim();
        txtMobileNumber.Text = txtMobileNumber.Text.Trim();
        txtOtherContactNumber.Text = txtOtherContactNumber.Text.Trim();
        txtEmailAddress.Text = txtEmailAddress.Text.Trim();

        if (txtEmailAddress.Text.Length == 0 && txtHomePhoneNumber.Text.Length == 0 && txtMobileNumber.Text.Length == 0 && txtOtherContactNumber.Text.Length == 0)
        {
            lblMessage.Text += "Guardian's Contact Infomation are NOT sufficient!<br/>";
            _retValue = false;
        }
        else
        {

            _retValue = true;
        }

        args.IsValid = _retValue;
    }

    protected void DOB_ServerSideValidation(object source, ServerValidateEventArgs args)
    {
        bool _retValue = true;
        DateTime _dtDOB = DateTime.Now;
        string _strDOB = string.Empty;

        if (ddlDOBDay.Text != "-1" && ddlDOBMonth.Text != "-1" && ddlDOBYear.Text != "-1")
        {
            _strDOB = ddlDOBDay.Text + "/" + ddlDOBMonth.SelectedItem.Text + "/" + ddlDOBYear.Text.ToString();
            if (!SIS.Utilities.General.GetDateTime(_strDOB, out _dtDOB))
            {

                lblMessage.Text += _strDOB + "  " + " Guardian's DOB is invalid!<br/>";
                _retValue = false;
            }
            else
            {
                _retValue = true;
                //lblMessage.Text += "Student DOB: " + _dtDOB.ToString("dd/MMM/yyyy") + "<br/>";
            }
        }
        else
        {
            lblMessage.Text += "Select Guardian DOB.<br/>";
            _retValue = false;
        }
        args.IsValid = _retValue;
    }


    protected void grvStudentProfile_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (grvStudentProfile.SelectedIndex >= 0)
        {
            DataKey _selectedDataKey = grvStudentProfile.SelectedDataKey;
            int _studentAccountKey = Convert.ToInt32(_selectedDataKey[0]);

            if (_studentAccountKey > 0)
            {
                lblStudentUserAccountKey.Text = _studentAccountKey.ToString();
                if (LoadStudentInfo(_studentAccountKey))
                {
                    divStudentDetails.Visible = true;
                    hplStudent.NavigateUrl = "~/student/?id=" + _studentAccountKey.ToString();
                    tbcEntry.Enabled = true;
                    btnNew.Enabled = true;
                    btnSubmit.Enabled = true;
                    lblTopMessage.Text = "Add new guardian - " + DateTime.Now.ToString("dddd, MMMM dd, yyyy");
                }
                else
                {
                    btnSubmit.Enabled = false;
                    btnNew.Enabled = false;
                    tbcEntry.Enabled = false;
                }
            }
        }
    }

    protected void gvRelationList_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (gvRelationList.SelectedIndex >= 0)
        {
            DataKey _selectedDataKey = gvRelationList.SelectedDataKey;
            int _gsAutoID = Convert.ToInt32(_selectedDataKey[0]);
            int _studentAccountKey = Convert.ToInt32(_selectedDataKey[1]);
            int _guardianAccountKey = Convert.ToInt32(_selectedDataKey[2]);

            if (_studentAccountKey > 0 && _guardianAccountKey > 0 && _gsAutoID > 0)
            {
                lblStudentGuardianRelationTypeKey.Text = _gsAutoID.ToString();
                lblStudentUserAccountKey.Text = _studentAccountKey.ToString();
                lblGuardianAccountKey.Text = _guardianAccountKey.ToString();
                LoadGuardianInfo(_guardianAccountKey);
                lblTopMessage.Text = "Update Guardian/Family detail - " + DateTime.Now.ToString("dddd, MMMM dd, yyyy");
            }
        }
    }



    protected void btnAddNewStudent_Click(object sender, EventArgs e)
    {
        Response.Redirect("default.aspx");
    }

    protected void btnAddNewFamily_Click(object sender, EventArgs e)
    {
        if (lblStudentUserAccountKey.Text != "-1")
        {
            Response.Redirect("guardian-detail.aspx?id=" + lblStudentUserAccountKey.Text);
        }
    }

    protected void chkSameAsResident_CheckedChanged(object sender, EventArgs e)
    {
        //divUnitNo.Visible = !chkSameAsResident.Checked;
        //divStreetName.Visible = !chkSameAsResident.Checked;
        //divCountry.Visible = !chkSameAsResident.Checked;
        //divCity.Visible = !chkSameAsResident.Checked;

        if (lblStudentUserAccountKey.Text == "-1")
        {
            chkSameAsResident.Checked = false;
            return;
        }

        if (chkSameAsResident.Checked)
        {
            txtUnitNo.Text = txtSRUnitNo.Text;
            txtStreetName.Text = txtSRStreetName.Text;
            ddlCountry.Text = ddlSRCountry.Text;
            ddlCountry_SelectedIndexChanged(sender, e);
            if (ddlDistrict.Items.Count > 0)
            {
                ddlDistrict.Text = ddlSRDistrict.Text;
                ddlDistrict_SelectedIndexChanged(sender, e);
                if (ddlCity.Items.Count > 0)
                {
                    ddlCity.Text = ddlSRCity.Text;
                }
            }

            txtPostCode.Text = txtSRPostCode.Text;
        }

        txtUnitNo.Enabled = !chkSameAsResident.Checked;
        txtStreetName.Enabled = !chkSameAsResident.Checked;
        ddlCountry.Enabled = !chkSameAsResident.Checked;
        ddlDistrict.Enabled = !chkSameAsResident.Checked;
        ddlCity.Enabled = !chkSameAsResident.Checked;
        txtPostCode.Enabled = !chkSameAsResident.Checked;

        rfvUnitNo.Enabled = !chkSameAsResident.Checked;
        rfvStreetName.Enabled = !chkSameAsResident.Checked;
        rfvCountry.Enabled = !chkSameAsResident.Checked;
        rfvDistrict.Enabled = !chkSameAsResident.Checked;
        rfvCity.Enabled = !chkSameAsResident.Checked;
        rfvPostCode.Enabled = !chkSameAsResident.Checked;

        if (chkSameAsResident.Checked)
        {
            chkSameAsResident.ForeColor = System.Drawing.Color.Red;
        }
        else
        {
            chkSameAsResident.ForeColor = System.Drawing.Color.Green;
        }
    }

    protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
    {
        _common.LoadDistrictCodeDDL(ddlDistrict, Convert.ToInt16(ddlCountry.Text), string.Empty);
        //if (ddlDistrict.Items.Count > 0)
        //{
        //    ddlDistrict.SelectedIndex = 0;
        //    ddlDistrict_SelectedIndexChanged(sender, e);
        //}

    }

    protected void ddlBCountry_SelectedIndexChanged(object sender, EventArgs e)
    {
        _common.LoadDistrictCodeDDL(ddlBDistrict, Convert.ToInt16(ddlBCountry.Text), string.Empty);
        //if (ddlBDistrict.Items.Count > 0)
        //{
        //    ddlBDistrict.SelectedIndex = 0;
        //    ddlBDistrict_SelectedIndexChanged(sender, e);
        //}
    }

    protected void ddlDistrict_SelectedIndexChanged(object sender, EventArgs e)
    {
        _common.LoadCityCodeDDL(ddlCity, Convert.ToInt32(ddlDistrict.Text), Convert.ToInt16(ddlCountry.Text), string.Empty);
    }

    protected void ddlBDistrict_SelectedIndexChanged(object sender, EventArgs e)
    {
        _common.LoadCityCodeDDL(ddlBCity, Convert.ToInt32(ddlBDistrict.Text), Convert.ToInt16(ddlBCountry.Text), string.Empty);
    }

    protected void ddlSRCountry_SelectedIndexChanged(object sender, EventArgs e)
    {
        _common.LoadDistrictCodeDDL(ddlSRDistrict, Convert.ToInt16(ddlSRCountry.Text), string.Empty);
    }

    protected void ddlSRDistrict_SelectedIndexChanged(object sender, EventArgs e)
    {
        _common.LoadCityCodeDDL(ddlSRCity, Convert.ToInt32(ddlSRDistrict.Text), Convert.ToInt16(ddlSRCountry.Text), string.Empty);
    }
}
